def groupAnagrams(strs):
    mp={}
    for s in strs:
        key=''.join(sorted(s))
        #print(key)
        if key in mp:
            mp[key].append(s)
        else:
            mp[key]=[s]
    ans=[]
    for lst in mp.values():
        ans.append(lst)
    return ans 

strs = ["eat", "tea", "tan", "ate", "nat", "bat"]
print(groupAnagrams(strs))